use chrono::{NaiveDate, NaiveDateTime, NaiveTime, Utc};
use idgenerator::{IdGeneratorOptions, IdInstance};

pub fn init() -> anyhow::Result<()> {
    let options = IdGeneratorOptions::new()
        .base_time(
            NaiveDateTime::new(
                NaiveDate::from_ymd_opt(2025, 1, 1).unwrap(),
                NaiveTime::from_hms_opt(0, 0, 0).unwrap(),
            ).and_local_timezone(Utc).unwrap().timestamp_millis()
        )
        .worker_id(1)
        .worker_id_bit_len(4);
    Ok(IdInstance::init(options)?)
}

pub fn next_id_str() -> String {
    IdInstance::next_id().to_string()
}

pub fn next_id() -> i64 {
    IdInstance::next_id()
}